package event.money.tracker;

import MTClient.ClientLogic;
import MTClient.MTConstant;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class MainTabView extends TabActivity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    setContentView(R.layout.main_tabview);
	    
	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, MainEvents.class);

	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("events").setIndicator("Events")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // Do the same for the other tabs
	    intent = new Intent().setClass(this, MainContacts.class);
	    spec = tabHost.newTabSpec("contacts").setIndicator("Contacts")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    intent = new Intent().setClass(this, MainNotifications.class);
	    spec = tabHost.newTabSpec("notifications").setIndicator("Notifications")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    tabHost.setCurrentTab(1);
	    
	    //ListView ContactListView = (ListView)findViewById(R.id.ContactListView01);
    	//ContactListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	}
	

	public void setTab(int tab) {
			getTabHost().setCurrentTab(tab);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.main_menu, menu);
	    return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	    case R.id.Test_SyncContacts:
	    	
	    	Log.e( "Money", "Request ID :" + MTConstant.MT_REQID_SYNCHRONIZE_CONTACT_LIST);
			//mClientTCP.SendRequest(MTConstant.MT_REQID_SYNCHRONIZE_CONTACT_LIST );
	    	ClientLogic.GetInstance().SendSynContactListRequest();
	       
	        return true;
	    case R.id.Test_AddEvent:

	    	Log.e( "Money", "Request ID :" + MTConstant.MT_REQID_CREATE_EVENT);
//			mRequestID = MTConstant.MT_REQID_CREATE_EVENT;
			ClientLogic.GetInstance().SendCreateEventRequest( "Write Program", "1 2 3 4", "Poly M Core" );
			//mClientTCP.SendRequest(MTConstant.MT_REQID_CREATE_EVENT, this );
	    	
	        return true;
	        
	    case R.id.Test_SyncLocalDB:
	    	
	    	Log.e( "Money", "Request ID :" + MTConstant.MT_REQID_SYNCHRONIZE_CONTACT_LIST);
	    	ClientLogic.GetInstance().SendSynLocalDBRequest();
	       
	        return true;
	    case R.id.Test_SyncServer:
	    	
	    	Log.e( "Money", "Request ID :" + MTConstant.MT_REQID_SYNCHRONIZE_DATA_FROM_SERVER );
			ClientLogic.GetInstance().SendSynServerDBRequest();
	       
	        return true;
	    case R.id.Test_TakeEvent:
	    	
	    	Log.e( "Money", "Request ID :" + MTConstant.MT_REQID_STOCK_TAKE_EVENT );
			ClientLogic.GetInstance().SendStackTakeEventRequest("1");
	       
	        return true;
	    case R.id.DelSharedPrefs:
	    	
	    	ClientLogic.GetInstance().del_shared_prefs();
	    	
	        return true;    
	    case R.id.DelLocalSql:
	    	
	    	ClientLogic.GetInstance().del_sqldb();
	    	
	        return true; 
	    case R.id.exit:
	    	
	    	finish();
	    	
	        return true;
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}

}
